import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store/index'
import axios from 'axios';
import ElementUI, {Message} from 'element-ui';
import './app.scss'
import echarts from 'echarts';
import 'element-ui/lib/theme-chalk/index.css';
import "babel-polyfill";
import promise from 'es6-promise';

promise.polyfill();
Vue.config.productionTip = false

Vue.use(ElementUI);
Vue.config.productionTip = false;
Vue.prototype.$axios = axios;
Vue.prototype.$echarts = echarts;
Vue.prototype.$message = Message;
axios.defaults.withCredentials = true;


//路由切换
router.beforeEach((to, from, next) => {
    let menu = JSON.parse(localStorage.getItem('menus'));
    menu = menu ? menu : [];
    //默认可通过的路由
    let defaultUrl = [{url: 'chartMain', children: []}, {url: 'notFound', children: []}, {url: 'login', children: []}]
    menu = [...menu, ...defaultUrl];
    let flag = false;
    menu.forEach(item => {
        if (item.url === to.name) {
            flag = true;
        }
        item.children.forEach(c => {
            if (c.url === to.name) {
                flag = true;
            }
        })
    })

    if (flag) {
        next()
    } else {
        next('/notFound')
    }
})


new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')


